function view_layer_temp(template,ROIs,bv,fnames)

filename1=(['\\argon\zmarpawe\ROIs\' strrep(strrep(fnames{1},'S1-T',''),'_ch525.bin','') 'template']);%'.png']);
filename2=(['\\argon\zmarpawe\ROIs\' strrep(strrep(fnames{1},'S1-T',''),'_ch525.bin','') 'ROIs']);%'.png']);
if isa(ROIs,'cell')
    x=[0.01 0.5 0.01 0.5];
    y=[0.5 0.5 0.01 0.01];
    figure('Visible','off');
    set(gcf,'menubar','none')
    set(gcf,'position',[1        1081        1920        1058])
    for ynp=1:4
        hold on
        subplot(2,2,ynp)
        set(gca,'position',[x(ynp) y(ynp) 0.47 0.47])
        imagesc(template{ynp});colormap gray;
        title(['layer: ' num2str(ynp)],'color','red')
        axis off
    end
    print(gcf,'-dbmp',filename1)
    
    figure('color','black','Visible','off');
    set(gcf,'menubar','none')
    set(gcf,'position',[1        1081        1920        1058])
    for unp=1:4
        hold on
        subplot(2,2,unp)
        set(gca,'position',[x(unp) y(unp) 0.47 0.47])
        % plot template with cells overlayed
        max_cont=mean(template{unp}(:))+2*std(template{unp}(:));
        min_cont=mean(template{unp}(:))-2*std(template{unp}(:));
        
        % hf = figure(1002);
        % set(hf,'menubar','none');
        % ha = axes('position',[0 0 1 1]);
        
        tmp=(template{unp}-min_cont)/(max_cont-min_cont);
        tmp(tmp>1)=1;
        tmp(tmp<0)=0;
        
        t_mask=zeros(size(template{unp}));
        bv_mask=zeros(size(template{unp}));
        
        for ind=1:length(ROIs{unp})
            t_mask(ROIs{unp}(ind).indices)=1;
            bv_mask(bv{unp}.indices)=1;
        end
        
        overlay(:,:,1)=tmp;
        overlay(:,:,2)=bwperim(t_mask);
        overlay(:,:,3)=bwperim(bv_mask);
        hi=imagesc(overlay);
        hold on
        
        for ind=1:length(ROIs{unp})
            [txt_x,txt_y]=ind2sub(size(template{unp}),min(ROIs{unp}(ind).indices));
            ht(ind)=text(txt_y,txt_x-10,num2str(ind),'color','w','fontweight','bold','fontsize',6);
        end
        axis off
    end
    print(gcf,'-dbmp',filename2)
else
    figure('Visible','off');
    set(gcf,'menubar','none')
    set(gcf,'position',[1        1081        1920        1058])
    hold on
    imagesc(template);
    colormap gray;
    axis off
    print(gcf,'-dbmp',filename1)
    
    figure('color','black','Visible','off');
    set(gcf,'menubar','none')
    set(gcf,'position',[1        1081        1920        1058])
    
    hold on
    % plot template with cells overlayed
    max_cont=mean(template(:))+2*std(template(:));
    min_cont=mean(template(:))-2*std(template(:));
    
    % hf = figure(1002);
    % set(hf,'menubar','none');
    % ha = axes('position',[0 0 1 1]);
    
    tmp=(template-min_cont)/(max_cont-min_cont);
    tmp(tmp>1)=1;
    tmp(tmp<0)=0;
    
    t_mask=zeros(size(template));
    bv_mask=zeros(size(template));
    
    for ind=1:length(ROIs)
        t_mask(ROIs(ind).indices)=1;
        bv_mask(bv.indices)=1;
    end
    
    overlay(:,:,1)=tmp;
    overlay(:,:,2)=bwperim(t_mask);
    overlay(:,:,3)=bwperim(bv_mask);
    hi=imagesc(overlay);
    hold on
    
    for ind=1:length(ROIs)
        [txt_x,txt_y]=ind2sub(size(template),min(ROIs(ind).indices));
        ht(ind)=text(txt_y,txt_x-10,num2str(ind),'color','w','fontweight','bold','fontsize',6);
    end
    axis off
    
    print(gcf,'-dbmp',filename2)
end